<template>
  <div class="list-table">
    <!--  GP填报账号注册申请列表  -->
    <!--    <div class="area-header">-->
    <!--      <span class="area-header-title">{{ $t('GP填报账号申请') }}</span>-->
    <!--    </div>-->
    <el-form ref="queryForm" :model="queryParams" :inline="true" @submit.native.prevent>
      <el-form-item :label="$t('管理人名称')" prop="gpName">
        <el-input
          v-model="queryParams.gpName"
          :placeholder="$t('管理人名称')"
          clearable
          @keyup.enter.native="queryHandle"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="queryHandle">{{ $t('搜索') }}</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">{{ $t('重置') }}</el-button>
      </el-form-item>
    </el-form>
    <el-table v-loading="loading" tooltip-effect="darkTable" :data="bfPortalRegisterDataList" border>
      <el-table-column :label="$t('序号')" type="index" align="center" show-overflow-tooltip width="50">
        <template slot-scope="scope">
          {{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}
        </template>
      </el-table-column>
      <el-table-column :label="$t('管理人名称')" align="center" prop="gpName" min-width="220" />
      <el-table-column :label="$t('管理人简称')" align="center" prop="gpShortName" min-width="130" />
      <el-table-column :label="$t('登陆名')" align="center" prop="userName" min-width="130" />
      <el-table-column :label="$t('手机')" align="center" prop="phone" min-width="130" />
      <el-table-column :label="$t('邮箱')" align="center" prop="email" min-width="150" />
      <el-table-column :label="$t('提交时间')" align="center" prop="createTime" width="130">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('审核状态')" align="center" prop="status" width="130" />
      <el-table-column :label="$t('审核人')" align="center" prop="applyUserName" width="120" />
      <el-table-column :label="$t('操作')" align="center" class-name="small-padding fixed-width" width="160">
        <template slot-scope="scope">
          <el-button
            v-if="scope.row.status === '待审核'"
            v-hasPermi="['bfPortal:register:edit']"
            size="small"
            type="text"
            icon="el-icon-s-custom"
            @click="asyncRegisterData(scope.row)"
          >{{ $t('审核通过') }}
          </el-button>
          <el-button
            v-if="scope.row.status === '待审核'"
            v-hasPermi="['bfPortal:register:edit']"
            size="small"
            type="text"
            icon="el-icon-s-custom"
            @click="rejectPortalRegisterData(scope.row)"
          >{{ $t('驳回') }}
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { listBfPortalRegisterUser, asyncRegisterData, rejectPortalRegisterData } from '@/api/bf/portal/bfPortalRegisterUser'

export default {
  data() {
    return {
      // 账号审批数据遮罩层
      loading: true,
      // 账号审批数据总条数
      total: 0,
      // 子基金填报-注册账号数据审核表格数据
      bfPortalRegisterDataList: [],
      // 审批状态字典
      statusOptions: [],
      // 查询参数
      queryParams: {
        dataType: '',
        pageNum: 1,
        pageSize: 10
      },
      // 表单参数
      form: {}
    }
  },
  created() {
    this.getList()
    this.getDicts('work_flow_status').then(response => {
      this.statusOptions = response.data
    })
  },
  methods: {
    /** 查询填报账号审核数据审核列表 */
    getList() {
      this.loading = true
      listBfPortalRegisterUser(this.queryParams).then(response => {
        this.bfPortalRegisterDataList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    // 审批状态字典翻译
    statusFormat(row) {
      return this.selectDictLabel(this.statusOptions, row.status)
    },
    // 表单重置
    reset() {
      this.form = {
        gpName: undefined,
        status: undefined
      }
      this.resetForm('form')
    },
    /** 搜索按钮操作 */
    queryHandle() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.queryHandle()
    },
    // 账号申请通过
    asyncRegisterData(row) {
      if (row.id !== '' && row.id !== undefined) {
        this.$confirm(this.$t('是否确认通过?'), this.$t('警告'), {
          confirmButtonText: this.$t('确定'),
          cancelButtonText: this.$t('取消'),
          type: 'warning'
        }).then(() => {
          this.loading = true
        }).then(function() {
          return asyncRegisterData(row.id)
        }).then(() => {
          this.getList()
          this.msgSuccess(this.$t('审核通过!'))
        }).catch(function() {
          this.msgError(this.$t('审核未通过!'))
        })
      }
    },
    // 驳回数据 - 账号申请
    rejectPortalRegisterData(row) {
      if (row.id !== '' && row.id !== undefined) {
        this.$confirm(this.$t('是否确认驳回?'), this.$t('警告'), {
          confirmButtonText: this.$t('确定'),
          cancelButtonText: this.$t('取消'),
          type: 'warning'
        }).then(() => {
          this.loading = true
        }).then(function() {
          return rejectPortalRegisterData(row.id)
        }).then(() => {
          this.getList()
          this.msgSuccess(this.$t('已驳回!'))
        }).catch(function() {
          this.msgError(this.$t('驳回失败!'))
        })
      }
    }
  }
}
</script>
